import { Module } from 'vuex'

interface ITabbar {
  iconPath: string
  selectedIconPath: string
  text: string
  pagePath: string
}
interface ISetting {
  bgColor: string
  activeColor: string
  inactiveColor: string
}

interface IState {
  list: ITabbar[]
  setting: ISetting
  modulesList: any
  isCurrentActivityBar: boolean
  platIndexData: any
  useWXTabBar: boolean
}

const store: Module<IState, unknown> = {
  namespaced: true,
  state() {
    return {
      list: [],
      setting: {
        bgColor: '#ffffff',
        activeColor: '#248DFA',
        inactiveColor: '#262626',
      },
      modulesList: [],
      isCurrentActivityBar: false,
      useWXTabBar: false,
      platIndexData: {
        templateVariable: {},
        searchText: [],
      },
    }
  },
  // 只能同步
  mutations: {
    initData(state) {
      state.list = []
      state.modulesList = []
    },
    changeList(state, list) {
      state.list = list
    },
    changeSetting(state, setting) {
      state.setting = setting
    },
    changeModulesList(state, list) {
      state.modulesList = list
    },
  },

  actions: {
    async setList(context) {
      const list = [
        {
          iconPath: require('@/static/home.png'),
          selectedIconPath: require('@/static/home_active.png'),
          text: '首页',
          pagePath: '/pages/main/index',
        },
        {
          iconPath: require('@/static/profile.png'),
          selectedIconPath: require('@/static/profile_active.png'),
          text: '我的',
          pagePath: '/pages/main/profile',
        },
      ]
      context.commit('changeList', list)
    },
  },
}

export default store
